﻿using Bangle.BLL;
using Bangle.Model;
using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class System_Login : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (IsPostBack)
        {
            CheckUser();
        }
    }

    private void CheckUser()
    {
        string Account = Request.Form["Account"];
        string Password = Request.Form["Password"];
        string ValidCode = Request.Form["ValidCode"];
        if (Account.Length <= 0)
        {
            Alert("请输入帐号！");
            return;
        }
        if (Password.Length <= 0)
        {
            Alert("请输入密码！");
            return;
        }
        if (ValidCode.Length <= 0)
        {
            Alert("请验请码密码！");
            return;
        }
        if (Session["CheckCode"] != null && ValidCode.ToUpper() != Session["CheckCode"].ToString())
        {
            Alert("验证码输入不正确！");
            return;
        }

        Session["CheckCode"] = null;

        UserSession user = new UserSession();
        user = new Sys_UserBLL().UserLogin(Account, Password);
        if (user == null)
        {
            Alert("帐号或密码输入不正确！");
        }
        else
        {
            Session["LoginUser"] = user;
            Response.Redirect("~/Admin/Main.aspx");
        }
    }

    private void Alert(string message)
    {
        Page.ClientScript.RegisterStartupScript(this.GetType(), "提示信息", "<script>alert(\"" + message + "\")</script>");
    }
}
